/* < 0074888 xuyinwen 20151031 add > */
package com.android.hw.projectmenu;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.util.Log;
import android.app.Activity;
import android.os.SystemClock;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

public class SecretReceiver extends BroadcastReceiver {

    private static final String TAG = "SecretReceiver";
    private static final String SECRET_CODE = "android.provider.Telephony.SECRET_CODE";

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        Log.d(TAG, "action = " + intent.getAction());
        if (intent.getAction().equals(SECRET_CODE) && appIsInstalled(context, "com.android.runintest")) {
            Intent startRunInTestActivity = new Intent();
            startRunInTestActivity.setClassName("com.android.runintest",
                    "com.android.runintest.RunInTestActivity");
            startRunInTestActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(startRunInTestActivity);
        }
    }

    public  boolean appIsInstalled(Context context, String packageName){
        try {
            PackageManager pm = context.getPackageManager();
            pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        } catch (NameNotFoundException e) {
            Log.d(TAG, "NameNotFoundException  " + e);
            return false;
        }
        return true;
    }
}
